﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;

namespace ETC
{
    public class CurrencyRate
    {
        public static string CurrentRate(string strBaseCurrency, string strTargetCurrency)
        {
            string strReturn = "0.0";

            string strURL = "";
            strURL = String.Format("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency={0}&ToCurrency={1}", strBaseCurrency.ToUpper(), strTargetCurrency.ToUpper());

            //string strData = Communication.GetRequestData(strURL);

            //if (strData.Length == 0)
            //    return strReturn;

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(strURL);

                strReturn = xmlDoc.DocumentElement.InnerText;
                
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            

            return strReturn;
        }

        public static string CurrentRate()
        {
            return CurrentRate("USD", "KRW");
        }
    }
}
